<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <div id="app">
        <com @parent="show"></com>
    </div>
    <template id="tmp">
        <div>
            <h1>这是子组件</h1>
            <input type="button" value="点击子组件会调用父组件的方法" @click="myclick">
        </div>
    </template>
    <script>
    var com = {
        template:"#tmp",
        data(){
            return{
                sonmsg:"父组件将方法传到子组件的同时，子组件将值传个父组件"
            }
        },
        methods: {
            myclick(){
                this.$emit('parent',this.sonmsg)
            }
        },
    }
    var vm = new Vue({
        el:"#app",
        data:{
            parentformson:null
        },
        methods: {
            show(data){
                console.log("这是父组件上的方法----" + data)
                console.log(data)
                this.parentformson = data
                console.log(this.parentformson)
            }
        },
        components:{
            com
        }
    })
    </script>
</body>
</html>